# 函数多个返回值
# def fun(a,b):
#     return a+b, a-b, a*b, a/b
# num1=int(input("Count Number\nEnter a number: "))
# icon=input("Enter an operator (+,-,*,/): ")
# num2=int(input("Enter another number: "))
# add, sub, mul, div = fun(num1,num2)
# if icon=="+":
#     print(add)
# elif icon=="-":
#     print(sub)
# elif icon=="*":
#     print(mul)
# elif icon=="/":
#     print(int(div))
# else:
#     print("Invalid operator")


# 匿名函数
# def counted(add, sub, mul, div,num1,num2,icon):
#     if icon=="+":
#         add(num1,num2)
#     elif icon=="-":
#         sub(num1,num2)
#     elif icon=="*":
#         mul(num1,num2)
#     elif icon=="/":
#         div(num1,num2)
#     else:
#         print("Invalid operator")
# def add(a,b):
#     print(a+b)
# def sub(a,b):
#     print(a-b)
# def mul(a,b):
#     print(a*b)
# def div(a,b):
#     print(int(a/b))
# num1=int(input("Count Number\nEnter a number: "))
# icon=input("Enter an operator (+,-,*,/): ")
# num2=int(input("Enter another number: "))
# counted(add, sub, mul, div,num1,num2,icon)


# lambda函数
# num1=int(input("Count Number\nEnter a number: "))
# icon=input("Enter an operator (+,-,*,/): ")
# num2=int(input("Enter another number: "))
# def counted(add, sub, mul, div,num1,num2,icon):
#     if icon=="+":
#         add(num1,num2)
#     elif icon=="-":
#         sub(num1,num2)
#     elif icon=="*":
#         mul(num1,num2)
#     elif icon=="/":
#         div(num1,num2)
#     else:
#         print("Invalid operator")
# counted(lambda a,b:print(a+b), lambda a,b:print(a-b), lambda a,b:print(a*b), lambda a,b:print(int(a/b)),num1,num2,icon) # 匿名函数


# 文件操作
# f=open("test.md","r",encoding="utf-8")
# print(type(f))
# print(f.read())

# for line in open('test.md','r',encoding='utf-8'):print(line)

# count=0
# with open('test.md','r',encoding='utf-8') as f:
#     for line in f:
#         for word in line:
#             if word=='#':
#                 count+=1
#         print(line)
#     print(count)

#
# r=open('test.md','r',encoding='utf-8')
# back=open('test.md.txt','a',encoding='utf-8')
# for line in r:
#     line=line.strip()
#     if line.split('.')[1]=='test':
#         continue
#     back.write(line+'\n')
# r.close()

# 异常处理
# try:
#     f=open('test.try','r',encoding='utf-8')
# except:
#     print('文件打开失败')

# try:
#     # 1/0 # 除数为0，抛出ZeroDivisionError异常
#     print(name) # 未定义的变量，抛出NameError异常
# except Exception as e: # 捕获ZeroDivisionError和NameError异常
#     print(e)

# def func1():print(1/0)
# def func2():func1()
# def func3():
#     try:
#         func2()
#     except:
#         print('捕获到了异常') # 捕获到了异常
# func3()

# 自定义异常
class MyException(Exception):
    def __init__(self,msg):
        self.msg=msg
    def __str__(self):
        return self.msg
try:
    raise MyException('自定义异常')
except MyException as e:
    print(e)